<template>
  <el-form :model="ruleForm2" status-icon :rules="rules2" ref="ruleForm2" label-width="100px" class="demo-ruleForm">
    <el-form-item label="账号" prop="zhanghao">
      <el-input type="zhanghaoword" v-model="ruleForm2.zhanghao" autocomplete="off"></el-input>
    </el-form-item>
    <el-form-item label="密码" prop="mima">
      <el-input v-model.number="ruleForm2.mima"></el-input>
    </el-form-item>
    <el-form-item>
      <el-button type="primary" @click="submitForm('ruleForm2')">提交</el-button>
      <el-button @click="resetForm('ruleForm2')">重置</el-button>
    </el-form-item>
  </el-form>
</template>

<script >
  export default {
    data() {
      var checkmima = (rule, value, callback) => {
        if (!value) {
          return callback(new Error('请输入密码'));
        }else {
          callback();
        }
      };
      var validatezhanghao = (rule, value, callback) => {
        if (value === '') {
          callback(new Error('请输入账号'));
        }else {
          callback();
        }
      };
      return {
        ruleForm2: {
          zhanghao: '',
          mima: ''
        },
        rules2: {
          zhanghao: [
            { validator: validatezhanghao, trigger: 'blur' }
          ],
          mima: [
            { validator: checkmima, trigger: 'blur' }
          ]
        }
      };
    },
    methods: {
      submitForm(formName) {
        this.$refs[formName].validate((valid) => {
          if (valid) {
            alert('submit!');
            this.$axios.get('http://localhost:8001/selectAll')
              .then(function (response) {
                console.log(response.data);
              })
              .catch(function (error) {
                console.log(error);
              });
          } else {
            console.log('error submit!!');
            return false;
          }
        });
      },
      resetForm(formName) {
        this.$refs[formName].resetFields();
      }
    }
  }
</script>
<style scoped>
  .demo-ruleForm {
    text-align: center;
    margin-top: 15%;
    width: 30%;
    margin-left: 35%;

  }
</style>


